/*
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-30 20:05:27
 * @LastEditTime: 2020-03-23 17:36:20
 * @LastEditors: Please set LastEditors
 */
var FLD = function () {
    return {

        serverIP: '106.15.33.39:9981',

        shoppingMallServerIP: '106.15.33.39:9000',




        nativeRequest_shop(cmd, parm, callback) {
            var url = 'http://' + FLD.serverIP + '/Frame/ST1_FLD/ShippingHandler.aspx?cmd=' + cmd;
            if (FLD.getUserInfo()) {
                if (!parm.hasOwnProperty("h_userId")) {
                    parm.h_userId = FLD.getUserInfo().UserId;
                }
            }

            api.ajax({
                url: url,
                method: 'post',
                dataType: 'json',
                data: {
                    values: parm
                }
            }, function (ret, err) {
                console.log(JSON.stringify(err))
                if (ret) {
                    if (ret.status == 200) {
                        if (callback) callback(ret.data);
                    } else {
                        vm.showLoading = false;
                        vm.refreshLoading = false;
                        vm.ifConfirm = false;
                        if (cmd != 'triggerActivity') {
                            vm.$toast(ret.msg);
                        }

                    }
                } else {
                    vm.showLoading = false;
                    vm.refreshLoading = false;
                    vm.ifConfirm = false;
                    vm.$toast('程序好像出错了,请稍后再试');
                }
            });
        },

        formConfigAjax(cmd, parm, callback, showToast) {
            var url = 'http://' + FLD.serverIP + '/' + cmd;
            if (FLD.getUserInfo()) {
                parm.P_UserID = FLD.getUserInfo().UserID;
                parm.userId = FLD.getUserInfo().UserID;
            } else {
                parm.P_UserID = 0;
                parm.userId = 0;
            }
            $.post(url, parm, function (ret) {

                if (ret) {
                    if (ret.status == 200) {
                        if (callback) callback(ret.data);
                    } else {
                        // alert(JSON.stringify(ret))
                        if (vm) {
                            vm.showLoading = false;
                            vm.refreshLoading = false;
                            vm.ifConfirm = false;
                            if (showToast !== 'toast') {
                                vm.$toast('程序好像出错了,请稍后再试');
                            }

                        }

                    }
                } else {
                    if (vm) {
                        vm.showLoading = false;
                        vm.refreshLoading = false;
                        vm.ifConfirm = false;
                        if (showToast !== 'toast') {
                            if (err.code == 0) {

                                vm.$toast('无法访问当前网络,请检查设置后重试');
                            } else {
                                vm.$toast('程序好像出错了,请稍后再试\n' + 'errcode:' + err.code);
                            }

                        }

                    }
                }
            }, 'json')


        },

        // c_ajax(cmd, parm, succeswCallback, failCallback) {
        //     var url = 'http://' + FLD.serverIP + '/Frame/SqlData?cmdname=' + cmd + '&platform=' + api.systemType + '【' + api.deviceId + '】';

        //     if (parm.P_UserID) {
        //         parm.userId = parm.P_UserID;
        //     } else {
        //         if (FLD.getUserInfo()) {
        //             parm.P_UserID = FLD.getUserInfo().UserID;
        //             parm.userId = FLD.getUserInfo().UserID;
        //         } else {
        //             parm.P_UserID = 0;
        //             parm.userId = 0;
        //         }
        //     }

        //     api.ajax({
        //         headers: {
        //             'Version': api.appVersion,
        //             'PackageName': 'com.fldls.app'
        //         },
        //         url: url,
        //         method: 'post',
        //         dataType: 'json',
        //         data: {
        //             values: parm
        //         }
        //     }, function (ret, err) {
        //         if (ret && ret.status == 200) {
        //             if (succeswCallback) succeswCallback(ret.data);
        //         } else {
        //             if (failCallback) {
        //                 failCallback();
        //             } else {
        //                 if (vm) {
        //                     vm.showLoading = false;
        //                     vm.refreshLoading = false;
        //                     vm.ifConfirm = false;
        //                     vm.$toast('3|程序好像出错了,请稍后再试');

        //                 }
        //             }
        //         }
        //     });
        // },



        ajax(cmd, parm, callback, showToast) {
            var url = 'http://' + FLD.serverIP + '/Frame/SqlData?cmdname=' + cmd + '&platform=' + api.systemType + '【' + api.deviceId + '】';

            if (parm.P_UserID) {
                parm.userId = parm.P_UserID;
            } else {
                if (FLD.getUserInfo()) {
                    parm.P_UserID = FLD.getUserInfo().UserID;
                    parm.userId = FLD.getUserInfo().UserID;

                    // parm.P_UserID = 26;
                    // parm.userId = 26;
                } else {
                    parm.P_UserID = 0;
                    parm.userId = 0;
                }
            }

            api.ajax({
                headers: {
                    'Version': api.appVersion,
                    'PackageName': 'com.fldls.app'
                },
                url: url,
                method: 'post',
                dataType: 'json',
                data: {
                    values: parm
                }
            }, function (ret, err) {
                if (ret) {
                    if (ret.status == 200) {
                        if (callback) callback(ret.data);
                    } else {
                        if (vm) {
                            vm.showLoading = false;
                            vm.refreshLoading = false;
                            vm.ifConfirm = false;
                            if (showToast !== 'toast') {
                                vm.$toast('程序好像出错了,请稍后再试');
                            }
                        }

                    }
                } else {
                    if (vm) {
                        vm.showLoading = false;
                        vm.refreshLoading = false;
                        vm.ifConfirm = false;
                        if (showToast !== 'toast') {
                            if (err.code == 0) {
                                vm.$toast('无法访问当前网络,请检查设置后重试');
                            } else {
                                vm.$toast('程序好像出错了,请稍后再试\n' + 'errcode:' + err.code);
                            }

                        }

                    }
                }
            });
        },

        uploadFile(folder, fileSrc, callback) {
            var url = 'http://' + FLD.serverIP + '/Frame/uploadFile?dirName=' + folder;
            api.ajax({
                headers: {
                    'Version': api.appVersion,
                    'PackageName': 'com.fldls.app'
                },
                url: url,
                method: 'post',
                data: {
                    files: {
                        file: fileSrc
                    }
                }
            }, function (ret, err) {
                if (ret) {
                    if (ret.status && ret.status == 200) {
                        if (callback) callback(ret.data);
                    } else {
                        if (vm) {
                            vm.showLoading = false;
                            vm.refreshLoading = false;
                            vm.$toast('上传失败,请稍后再试');
                        }

                    }
                } else {
                    if (vm) {
                        vm.showLoading = false;
                        vm.refreshLoading = false;
                        vm.$toast('程序好像出错了,请稍后再试\n' + 'errcode:' + err.code);
                    }
                }
            });
        },

        nativeRequest_pay(cmd, parm, callback) {
            var url = 'http://' + FLD.serverIP + '/Frame/ST1_FLD/PayBusinessHandler.aspx?cmd=' + cmd;
            if (parm.P_UserID) {
                parm.userId = parm.P_UserID;
            } else {
                if (FLD.getUserInfo()) {
                    parm.P_UserID = FLD.getUserInfo().UserID;
                    parm.userId = FLD.getUserInfo().UserID;
                } else {
                    parm.P_UserID = 0;
                    parm.userId = 0;
                }
            }
            api.ajax({
                headers: {
                    'Version': api.appVersion,
                    'PackageName': 'com.fldls.app'
                },
                url: url,
                method: 'post',
                dataType: 'text',
                data: {
                    values: parm
                }
            }, function (ret, err) {
                if (ret) {
                    callback(ret)
                } else {
                    vm.showLoading = false;
                    vm.refreshLoading = false;
                    vm.ifConfirm = false;
                    vm.$toast('程序好像出错了,请稍后再试');
                }


            });
        },

        nativeRequest_vin(cmd, parm, callback) {
            var url = 'http://' + FLD.serverIP + '/Frame/ST1_FLD/VinHandler.aspx?cmd=' + cmd;
            api.ajax({
                headers: {
                    'Version': api.appVersion,
                    'PackageName': 'com.fldls.app'
                },
                url: url,
                method: 'post',
                dataType: 'text',
                data: {
                    values: parm
                }
            }, function (ret, err) {
                if (ret) {
                    var json_ret = JSON.parse(ret);
                    if (callback) callback(json_ret);
                } else {
                    if (cmd == 'SearchBusinessByVin' || cmd == 'SearchBusinessByOE' || cmd == 'SearchBusinessByPartsno' || cmd == 'SearchBusinessByFmsi') {
                        layer.open({
                            content: '未查询到数据,请确认查询内容!',
                            skin: 'msg',
                            time: 3
                        });

                    } else {
                        vm.$toast('程序好像出错了,请稍后再试\n' + 'errcode:' + err.code);
                    }
                    vm.showLoading = false;
                    vm.refreshLoading = false;
                    vm.ifConfirm = false;

                }
            });
        },

        nativeRequest_oilvin(cmd, parm, callback) {
            var url = 'http://' + FLD.serverIP + '/Frame/ST1_FLD/OilHandler.aspx?cmd=' + cmd;
            api.ajax({
                headers: {
                    'Version': api.appVersion,
                    'PackageName': 'com.fldls.app'
                },
                url: url,
                method: 'post',
                dataType: 'text',
                data: {
                    values: parm
                }
            }, function (ret, err) {
                if (ret) {
                    var json_ret = JSON.parse(ret);
                    if (callback) callback(json_ret);
                } else {
                    vm.showLoading = false;
                    vm.refreshLoading = false;
                    vm.ifConfirm = false;

                }
            });
        },

        nativeRequest_jyvin(cmd, parm, callback) {
            var url = 'http://' + FLD.serverIP + '/Frame/ST1_FLD/JY_VinHandler.aspx?cmd=' + cmd;
            api.ajax({
                headers: {
                    'Version': api.appVersion,
                    'PackageName': 'com.fldls.app'
                },
                url: url,
                method: 'post',
                dataType: 'text',
                data: {
                    values: parm
                }
            }, function (ret, err) {
                if (ret) {
                    var json_ret = JSON.parse(ret);
                    if (callback) callback(json_ret);
                } else {
                    if (cmd == 'SearchBusinessByVin' || cmd == 'SearchBusinessByOE' || cmd == 'SearchBusinessByPartsno' || cmd == 'SearchBusinessByFmsi') {
                        layer.open({
                            content: '未查询到数据,请确认查询内容!',
                            skin: 'msg',
                            time: 3
                        });

                    } else {
                        vm.$toast('程序好像出错了,请稍后再试\n' + JSON.stringify(err));
                    }
                    vm.showLoading = false;
                    vm.refreshLoading = false;
                    vm.ifConfirm = false;

                }
            });
        },

        nativeRequest_spvin(cmd, parm, callback) {
            var url = 'http://' + FLD.serverIP + '/Frame/ST1_FLD/SouPei_VinHandler.aspx?cmd=' + cmd;
            api.ajax({
                headers: {
                    'Version': api.appVersion,
                    'PackageName': 'com.fldls.app'
                },
                url: url,
                method: 'post',
                dataType: 'text',
                data: {
                    values: parm
                }
            }, function (ret, err) {
                if (ret) {
                    var json_ret = JSON.parse(ret);
                    if (callback) callback(json_ret);
                } else {
                    if (cmd == 'SearchBusinessByVin' || cmd == 'SearchBusinessByOE' || cmd == 'SearchBusinessByPartsno' || cmd == 'SearchBusinessByFmsi') {
                        layer.open({
                            content: '未查询到数据,请确认查询内容!',
                            skin: 'msg',
                            time: 3
                        });

                    } else {
                        vm.$toast('程序好像出错了,请稍后再试\n' + JSON.stringify(err));
                    }
                    vm.showLoading = false;
                    vm.refreshLoading = false;
                    vm.ifConfirm = false;

                }
            });
        },


        mustLogin(callback) {
            var user = api.getGlobalData({
                key: 'user'
            });
            if (!user) {
                api.openWin({
                    name: '登录',
                    url: '../../login.html',
                    animation: {
                        type: "movein",                //动画类型（详见动画类型常量）
                        subType: "from_bottom",       //动画子类型（详见动画子类型常量）
                        duration: 300                //动画过渡时间，默认300毫秒
                    },
                    reload: true,
                    slidBackEnabled: false
                })
            } else {
                callback();
            }
        },

        exitApp() {
            setTimeout(function () {
                api.addEventListener({
                    name: 'keyback'
                }, function (ret, err) {
                    api.toast({
                        msg: '再按一次返回键退出' + api.appName,
                        duration: 2000,
                        location: 'bottom'
                    });
                    api.addEventListener({
                        name: 'keyback'
                    }, function (ret, err) {
                        api.closeWidget({
                            id: 'A6019933686735',
                            retData: {
                                name: 'closeWidget'
                            },
                            silent: true
                        });
                    });
                    setTimeout(function () {
                        FLD.exitApp();
                    }, 2000)
                });
            }, 400);

        },
        dateFormat(date, fmt) {
            date = new Date(date)

            var a = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
            var o = {
                'Y': date.getFullYear(),
                'M+': date.getMonth() + 1, // 月份
                'd+': date.getDate(), // 日
                'h+': date.getHours(), // 小时
                'm+': date.getMinutes(), // 分
                's+': date.getSeconds(), // 秒
                'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
                'S': date.getMilliseconds(), // 毫秒
                'w': date.getDay(), // 周
                'W': a[date.getDay()], // 大写周
                'T': 'T'
            }
            if (/(y+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
            }
            for (var k in o) {
                if (new RegExp('(' + k + ')').test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[
                        k]).length)))
                }
            }
            return fmt
        },

        getFormatDate(date) {
            if (!date) date = new Date();
            var seperator1 = "-";
            var seperator2 = ":";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            var hour = date.getHours();
            var minute = date.getMinutes();
            var second = date.getSeconds();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            if (hour >= 0 && hour <= 9) {
                hour = "0" + hour;
            }
            if (minute >= 0 && minute <= 9) {
                minute = "0" + minute;
            }
            if (second >= 0 && second <= 9) {
                second = "0" + second;
            }
            var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
                + " " + hour + seperator2 + minute
                + seperator2 + second;
            return currentdate;
        },

        getFormatYearMonthTime(date) {
            if (!date) date = new Date();
            var seperator1 = "-";
            var seperator2 = ":";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            var hour = date.getHours();
            var minute = date.getMinutes();
            var second = date.getSeconds();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            if (hour >= 0 && hour <= 9) {
                hour = "0" + hour;
            }
            if (minute >= 0 && minute <= 9) {
                minute = "0" + minute;
            }
            var currentdate = date.getFullYear() + seperator1 + month;
            return currentdate;
        },

        getFormatDateTime(date) {
            if (!date) date = new Date();
            var seperator1 = "-";
            var seperator2 = ":";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            var hour = date.getHours();
            var minute = date.getMinutes();
            var second = date.getSeconds();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            if (hour >= 0 && hour <= 9) {
                hour = "0" + hour;
            }
            if (minute >= 0 && minute <= 9) {
                minute = "0" + minute;
            }
            var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
                + " " + hour + seperator2 + minute;
            return currentdate;
        },

        getClockFormatDate(date) {
            if (!date) date = new Date();
            var seperator1 = "-";
            var seperator2 = ":";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            var hour = date.getHours();
            var minute = date.getMinutes();
            var second = date.getSeconds();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            if (hour >= 0 && hour <= 9) {
                hour = "0" + hour;
            }
            if (minute >= 0 && minute <= 9) {
                minute = "0" + minute;
            }
            if (second >= 0 && second <= 9) {
                second = "0" + second;
            }
            var currentdate = hour + seperator2 + minute;
            return currentdate;
        },

        getChatFormatDate(date) {
            if (!date) date = new Date();
            var seperator1 = "-";
            var seperator2 = ":";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            var hour = date.getHours();
            var minute = date.getMinutes();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            if (hour >= 0 && hour <= 9) {
                hour = "0" + hour;
            }
            if (minute >= 0 && minute <= 9) {
                minute = "0" + minute;
            }
            var currentdate = month + seperator1 + strDate
                + " " + hour + seperator2 + minute;
            return currentdate;
        },

        getUserInfo() {
            if (window.localStorage.getItem('userInfo')) {
                return JSON.parse(window.localStorage.getItem('userInfo'))
            } else {
                return null;
            }
        }
    }
}()

// Vue.component('serve-img1', {
//     props: ['src'],
//     template: '<img :src="returnServeImg(src)" />',
//     methods: {
//         returnServeImg(src) {
//             if (src && src != 'null') {
//                 return 'http://' + FLD.serverIP + src;
//             } else {
//                 return '../../image/header.png';
//             }

//         }
//     }
// })
Vue.component('serve-img2', {
    props: ['src'],
    template: '<img :src="returnServeImg(src)" />',
    methods: {
        returnServeImg(src) {
            if (src) {
                return 'http://' + FLD.serverIP + src;
            } else {
                return '../../image/no.png';
            }

        }
    }
})

var systemType = window.localStorage.getItem('systemType');
var appTop = parseInt(window.localStorage.getItem('safeAreaTop'));
var appBottom = parseInt(window.localStorage.getItem('safeAreaBottom'));

$(function () {
    if (appTop) {
        $('.head').css({
            'padding-top': appTop + 'px',
            'height': appTop + 40 + 'px',
            'line-height': '40px'
        })
    } else {
        $('.head').css({
            'padding-top': appTop + 25 + 'px',
            'height': '65px',
            'line-height': '40px'
        })
    }
    // $('.body-no-bottom').css({
    //     'height': 'calc(100% - ' + (appTop + 40) + 'px)'
    // })
    // $('.body-with-bottom').css({
    //     'height': 'calc(100% - ' + (appTop + 90) + 'px)'
    // })

    // var windowHeight = $(window).height();
    // $(window).resize(function () {
    //     if ($(window).height() == windowHeight) {
    //         if ($('.bottom').length) {
    //             $('.body-with-bottom').css({
    //                 'height': 'calc(100% - ' + (appTop + 90) + 'px)'
    //             })
    //             $('.bottom').show();
    //         }
    //     } else if ($(window).height() < windowHeight) {
    //         if ($('.bottom').length) {
    //             $('.body-with-bottom').css({
    //                 'height': 'calc(100% - ' + (appTop + 40) + 'px)'
    //             })
    //             $('.bottom').hide();
    //         }
    //     }
    // })

    //vant下拉刷新与向上滚动的冲突问题解决
    setTimeout(function () {
        if (typeof (vm) != 'undefined') {
            if (vm.loadingDisabled != undefined) {
                $('.content').scroll(function () {
                    if ($(this).scrollTop() == 0) {
                        vm.loadingDisabled = false;
                    } else {
                        vm.loadingDisabled = true;
                    }
                })
            }
        }
    }, 200)
    //vue移动端点击方法300毫秒延迟问题解决
    if (typeof (FastClick) !== 'undefined') {
        FastClick.attach(document.body)
    }

})